//
//  CRKitConfig.m
//  TestPrj
//
//  Created by 朱铅峰 on 2020/8/6.
//  Copyright © 2020 Xing. All rights reserved.
//

#import "CRKitConfig.h"
#import "CRMediaItem.h"
#import "UIImage+CRKit.h"

@implementation CRKitConfig

+ (instancetype)instance {
    
    static dispatch_once_t once;
    static id __singleton__;
    dispatch_once( &once, ^{ __singleton__ = [[self alloc] init]; });
    return __singleton__;
}

- (instancetype)init {
    
    self = [super init];
    if (self) {
        [self applyDefaultSettings];
    }
    return self;
}

- (void)applyDefaultSettings {
    
    _messageInterval = 300;
    _messageLimit    = 20;
    _recordMaxDuration = 60.f;
    _placeholder = @"请输入消息";
    _inputMaxLength = 1000;
    _nickFont  = [UIFont systemFontOfSize:13.0];
    _nickColor = [UIColor darkGrayColor];
    _receiptFont  = [UIFont systemFontOfSize:13.0];
    _receiptColor = [UIColor darkGrayColor];
    _avatarType = CRKitAvatarTypeRounded;
    _cellBackgroundColor = CRKit_UIColorFromRGB(0xE4E7EC);
    _leftBubbleSettings  = [[CRKitSettings alloc] init:NO];
    _rightBubbleSettings = [[CRKitSettings alloc] init:YES];
}

/// 默认的更多面板的按钮配置
- (NSArray *)defaultMediaItems {
    
    return @[[CRMediaItem item:@"onTapMediaItemPicture:"
                   normalImage:[UIImage cr_imageInKit:@"bk_media_picture_normal"]
                 selectedImage:[UIImage cr_imageInKit:@"bk_media_picture_pressed"]
                         title:@"相册"],
             
             [CRMediaItem item:@"onTapMediaItemShoot:"
                   normalImage:[UIImage cr_imageInKit:@"bk_media_shoot_normal"]
                 selectedImage:[UIImage cr_imageInKit:@"bk_media_shoot_pressed"]
                         title:@"拍摄"],
             
             [CRMediaItem item:@"onTapMediaItemLocation:"
                   normalImage:[UIImage cr_imageInKit:@"bk_media_position_normal"]
                 selectedImage:[UIImage cr_imageInKit:@"bk_media_position_pressed"]
                         title:@"位置"],
    ];
}

- (CRKitSetting *)setting:(CRMessage *)message {
    
    CRKitSettings *settings = message.isOutgoingMsg? self.rightBubbleSettings : self.leftBubbleSettings;
    switch (message.messageType) {
        case CRMessageTypeText:
            return settings.textSetting;
        case CRMessageTypeImage:
            return settings.imageSetting;
        case CRMessageTypeLocation:
            return settings.locationSetting;
        case CRMessageTypeAudio:
            return settings.audioSetting;
        case CRMessageTypeVideo:
            return settings.videoSetting;
        case CRMessageTypeFile:
            return settings.fileSetting;
        case CRMessageTypeTip:
            return settings.tipSetting;
//        case CRMessageTypeNotification:
//        {
//            NIMNotificationObject *object = (NIMNotificationObject *)message.messageObject;
//            switch (object.notificationType)
//            {
//                case NIMNotificationTypeTeam:
//                    return settings.teamNotificationSetting;
//                case NIMNotificationTypeSuperTeam:
//                    return settings.superTeamNotificationSetting;
//                case NIMNotificationTypeChatroom:
//                    return settings.chatroomNotificationSetting;
//                case NIMNotificationTypeNetCall:
//                    return settings.netcallNotificationSetting;
//                default:
//                    break;
//            }
//            break;
//        }
        default:
            break;
    }
    return settings.unsupportSetting;
}

- (CRKitSetting *)repliedSetting:(CRMessage *)message {
    
    CRKitSettings *settings = message.isOutgoingMsg? self.rightBubbleSettings : self.leftBubbleSettings;
    return settings.repliedSetting;
}

@end
